﻿
using log4net.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ILogger = Microsoft.Extensions.Logging.ILogger;

namespace Log4_Net
{
    public class LogHelper : ILogHelper
    {
        public ILogger _logger = null;
        public LogHelper() {
            _logger = GetLogger();
        }
        public ILogger GetLogger()
        {
            if (_logger == null)
            {
                _logger = new LoggerFactory().AddLog4Net().CreateLogger("log");
            }
            return _logger;
        }

        public ILogger GetLogger<T>()
        {
            if (_logger == null)
            {
                _logger = new LoggerFactory().AddLog4Net().CreateLogger<T>();
            }
            return _logger;
        }
    }

    public static class Log4_Net {
        public static IServiceCollection AddLog4Net([NotNull] this IServiceCollection services)
        { 
            services.AddSingleton(typeof(ILogHelper), typeof(LogHelper));
            return services;
        }


    }
}
